JavaScript

Check Console for Output

For Explanation Click Here

Data Types in JS

1.What will be the output?
    let x = 5;
    let y = x;
    x = 10;
    console.log(x);
    console.log(y);
A:Output: 10, 5

2.What will be the output?
    let obj1 = { name: "Alice" };
    let obj2 = obj1;
    obj1.name = "Bob";
    console.log(obj1.name);
    console.log(obj2.name);
A:Output: Bob, Bob

3.What will be the output?
    let a = "hello";
    let b = 42;
    let c = true;
    let d = { key: "value" };
    let e = null;
    let f = undefined;
    console.log(typeof a);
    console.log(typeof b);
    console.log(typeof c);
    console.log(typeof d);
    console.log(typeof e);
    console.log(typeof f);
A:Output: string, number, boolean, object, object, undefined

4.What will be the output?
    let numbers = [10, 20, 30, 40, 50];
    console.log(numbers[2]);
    console.log(numbers[0]);
    console.log(numbers[numbers.length - 1]);
A:Output: 30, 10, 50

5.What will be the output?
    let fruits = ["apple", "banana", "mango"];
    fruits[1] = "orange";
    console.log(fruits);
A:Output: ["apple", "orange", "mango"]

6.What will be the output?
    let matrix = [
      [1, 2, 3],
      [4, 5, 6],
      [7, 8, 9]
    ];
    console.log(matrix[1][2]);
    console.log(matrix[2][0]);
A:Output: 6, 7

7.What will be the output?
    let person = {
      name: "John",
      age: 25,
      city: "New York"
    };
    console.log(person.name);
    console.log(person.age);
A:Output: John, 25

8.What will be the output?
    let car = {
      make: "Toyota",
      model: "Corolla",
      year: 2021
    };
    console.log(car["make"]);
    console.log(car["model"]);
A:Output: Toyota, Corolla

9.What will be the output?
    let book = {
      title: "The Great Gatsby",
      author: "F. Scott Fitzgerald"
    };
    book.author = "Anonymous";
    console.log(book.author);
A:Output: Anonymous

10.What will be the output?
    let student = {
      name: "Alice",
      grade: "A"
    };
    student.age = 20;
    console.log(student);
A:Output: {name: 'Alice', grade: 'A', age: 20}